﻿<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <title>服务升级</title>
    <style>
        .pagecontent {
            width: 100%;
            height: 100%;
            padding: 20px;
            box-sizing: border-box;
        }

        .pagecontent .toolarea {
            display: block;
            line-height: 40px;
        }

        .toolarea .spanstate {
            font-size: 14px;
            cursor: pointer;
            padding-left: 10px;
            padding-right: 10px;
        }

        .toolarea input[type=button] {
            display: inline-block;
            padding: 4px;
            border: 0;
            background-color: rgb(63, 218, 89);
            border-radius: 2px;
            cursor: pointer;
            padding-left: 20px;
            padding-right: 20px;
            color: white;
        }
        .toolarea .selected{
            font-weight: bold;
        }

        #chartarea {
            width: 100%;
            height: 500px;
            position: relative;
            margin: auto;
        }
    </style>
</head>

<body>


    <div class="pagecontent">
        <div class="toolarea">
            <span class="spanstate selected">实时</span>
            <span>|</span>
            <input type="text" value="" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:00:00'})" id="datemax"
                class="input-text Wdate datestart" style="width:180px;">
            <span>-</span>
            <input type="text" value="" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:00:00'})" id="datemax"
                class="input-text Wdate dateend" style="width:180px;">
            <input type="button" value="查询" onclick="_funcload();">
        </div>
        <!-- 工具选择区域 -->
        <div id="chartarea">

        </div>
    </div>


    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="../lib/jquery.contextmenu/jquery.contextmenu.r2.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <!-- <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> -->


    <script src="../lib/api.js"></script>
    <!-- <link href="../lib/page.min.css" rel="stylesheet" />
    <script src="../lib/page.min.js"></script> -->

    <script src="echarts.min.js"></script>

    <script>

        // var pageobject = null;

        var issecond = true;
        var linuxid = 1000;

        function _showpagedata(datas) {

            // var item = datas[k];
            //     var htmlStr = '<tr class="text-c">';
            //     htmlStr += '<td>' + item.id + '</td>';
            //     htmlStr += '<td>' + item.linuxPointId + '</td>';
            //     htmlStr += '<td>' + item.dataDate + '</td>';
            //     htmlStr += '<td>' + item.cpuUsed + '%</td>';
            //     htmlStr += '<td>' + item.cpU1 + '% --- '+item.cpU2+'% --- '+item.cpU3+'%</td>';
            //     htmlStr += '<td>' + item.memoryUsed + 'MB/'+item.memoryTotal+'MB</td>';
            //     htmlStr += '</tr>';
            //     hstr += htmlStr;


            var option = {
                title: {
                    text: ''
                },
                tooltip: {
                    trigger: 'axis'
                },
                toolbox: {
                    show: true,
                    feature: {
                        magicType: { show: true, type: ['stack', 'tiled'] },
                        saveAsImage: { show: true }
                    }
                },
                legend: {
                    data: ['CPU','内存占用','流量入','流量出']
                },
                xAxis: {
                    data: []
                },
                yAxis: [
                    {
                        type: 'value',
                        name: 'CPU',
                        min: 0,
                        max: 10,
                        position: 'left',
                        offset:30,
                        axisLabel: {
                            formatter: '{value}%'
                        }
                    },
                    {
                        type: 'value',
                        name: '内存占用',
                        position: 'left',
                        nameLocation: 'end',
                        offset: -30,
                        axisLabel: {
                            formatter: '{value}MB'
                        }
                    },
                    {
                        type: 'value',
                        name: '流量入',
                        position: 'right',
                        nameLocation: 'end',
                        offset: -40,
                        axisLabel: {
                            formatter: '{value}MB'
                        }
                    },
                    {
                        type: 'value',
                        name: '流量出',
                        position: 'right',
                        nameLocation: 'end',
                        offset: 40,
                        axisLabel: {
                            formatter: '{value}MB'
                        }
                    }
                ],
                series: []
            };

            var cpuarray = new Array();
            var memoryarray = new Array();

            var netinarray=new Array();
            var netoutarray=new Array();

            for (var k = 0; k < datas.length; k++) {
                var item = datas[k];
                option.xAxis.data.push(item.dataDate);
                cpuarray.push(item.cpuUsed);
                memoryarray.push(item.memoryUsed);
                netinarray.push(item.netIn);
                netoutarray.push(item.netOut);
            }

            // var maxval = Math.max(...cpuarray);
            // if (maxval < 50) {
            //     option.yAxis[0].max = parseInt(maxval * 3 + 1);
            //     console.log(option.yAxis[0].max);
            // } else {
            //     option.yAxis[0].max = 100;
            // }

            var maxval = Math.max(...cpuarray);
            if (maxval < 50) {
                option.yAxis[0].max = Number((maxval * 3)).toFixed(2);
                console.log(option.yAxis[0].max);
            } else {
                option.yAxis[0].max = 100;
            }


            option.series.push({smooth:true,  name: 'CPU', type: 'line', data: cpuarray, yAxisIndex: 0 });

            option.series.push({smooth:true,  name: '内存占用', type: 'line', data: memoryarray, yAxisIndex: 1 });

            option.series.push({smooth:true,  name: '流量入', type: 'line', data: netinarray, yAxisIndex: 2 });

            option.series.push({smooth:true,  name: '流量出', type: 'line', data: netoutarray, yAxisIndex: 3 });

            //初始化echarts实例
            var myChart = echarts.init(document.getElementById('chartarea'));

            //使用制定的配置项和数据显示图表
            myChart.setOption(option);




        }
        $(window).ready(function () {


            var uidstr = _apigetquery("id");
            if (uidstr != null) {
                linuxid = parseInt(uidstr);
            }

            $(".spanstate").on('click', function () {

                $(".spanstate").addClass("selected");
                var daynow = new Date();
                $(".datestart").val(daynow.Format("yyyy-MM-dd HH:00:00"));
                var daylater = new Date();
                daylater.setTime(daynow.getTime() + 1000 * 3600);
                $(".dateend").val(daylater.Format("yyyy-MM-dd HH:00:00"));
                issecond = true;
                _readpagedata(1);

            });
            var daynow = new Date();
            $(".datestart").val(daynow.Format("yyyy-MM-dd HH:00:00"));
            var daylater = new Date();
            daylater.setTime(daynow.getTime() + 1000 * 3600);
            $(".dateend").val(daylater.Format("yyyy-MM-dd HH:00:00"));

            _readpagedata(1);

            $(".inputword").keyup(function (event) {
                if (event.keyCode == 13) {
                    _readpagedata(1);
                }
            });

        });

        function _funcload() {
            issecond = false;
            $(".spanstate").removeClass("selected");
            _readpagedata(1);

        }

        function _readpagedata(page) {

            try {

                var datestart = new Date($(".datestart").val());

                var dateend = new Date($(".dateend").val());



                _apiget("/api/sheet/" + (issecond ? "linuxState" : "linuxTimeState") + "/listCharts?datestart=" + $(".datestart").val() + "&dateend=" + $(".dateend").val() + "&objectid=" + linuxid, true, function (code, obj) {
                    if (code == 200) {
                        var datas = obj.items;
                        _showpagedata(datas);
                        // pageobject.nums = obj.totalCount;
                        // var intid = parseInt(pageobject.nums / pageobject.counts); var less = parseInt(pageobject.nums % pageobject.counts); if (less > 0) { pageobject.pages = intid + 1; } else { pageobject.pages = intid; };
                    }
                });

            } catch (error) {
                layer.msg("时间格式不正确，请重新输入！" + error.message);
            }
            //var inputword = $(".inputword").val();




        }




    </script>


</body>

</html>